<%@ page contentType="text/html; charset=iso-8859-1" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page import="com.iMusic.businessLogicLayer.Account" %>
<%@ page import="com.iMusic.businessLogicLayer.Product" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>iMusic</title>

<script>
function validateAddToCart()
{
	var account = request.getSession().getAttribute("Account");
	if (account==null)
  	{
  		alert("Please login before you add product to your cart.");
  		return false;
  	}
}


</script>

</head>
<body>
<%
String error=request.getParameter("error");
if(error==null || error=="null"){
 error="";
}

String error2 = (String) request.getSession().getAttribute("Error");
if(error2==null || error2=="null"){
	 error2="";
	}


%>
<%
if (!error2.equals("")) {
%>
	<div style="text-align: right; color: rgb(255, 0, 0);"><%=error2%></div>
<%
}
%>	

<table style="text-align: left; width: 100%; height: 100%;" border="0"
cellpadding="2" cellspacing="2">
<tbody>

<form style="vertical-align: middle; text-align: center; " target="_top" name="Recalculate" onsubmit="return recalculate()" action="RecalculateCart" method="post" >

	<tr>
		<td style="vertical-align: top; width: 300px;"><br>
			<b>PRODUCT</b>
		</td>
		<td style="vertical-align: top; width: 100px;"><br>
			<b>PRICE<br> PER UNIT</b>
		</td>
		<td style="vertical-align: top; width: 100px;"><br>
			<b>QUANTITY</b>
		</td>
		<td style="vertical-align: top; width: 100px;"><br>
			<b>AMOUNT</b>
		</td>
	</tr>


	<c:forEach items="${Cart.getProducts()}" var="prod">
		<tr>
			<td style="vertical-align: top; width: 300px;"><br>
	            <b> ${prod.getName()}</b>&nbsp(${prod.getTypeName()})&nbsp<br>
	            <i>${prod.getCategoryName()}</i><br>
	            Price: $${prod.getPrice()}<br>
	            <c:if test="${prod.getUnitsInStock() >= 0}"> 
	            	In Stock: ${prod.getUnitsInStock()} units<br>
	            </c:if>
	        </td>
			<td style="vertical-align: top; width: 100px;"><br>
	        	<fmt:formatNumber value="${prod.getPrice()}" type="currency"/> 
	        </td>
			<td style="vertical-align: top; width: 100px;"><br>
				<c:if test="${prod.getTypeName().startsWith('MP3 download') == true }">
					1
				</c:if>
				<c:if test="${prod.getTypeName().startsWith('MP3 download') == false }">
		        	<input type="text" value="${Cart.getQuantity(prod)}" size="3" name="${prod.getProductId() }">
		        </c:if> 
	        </td>
			<td style="vertical-align: top; width: 100px;"><br>
	        	${Cart.calculateSubtotal(prod) } 
	        </td>
	    </tr>    
	</c:forEach>

	<tr>
		<td style="vertical-align: top; width: 300px;"><br>
		</td>
		<td style="vertical-align: top; width: 100px;"><br>
				<input type="submit" value="Recalculate" >
				<br>
				<br>
				
				</form>
				<c:if test="${Account == null}">
				 <form style="vertical-align: middle; " target="_top" action="checkoutFS.jsp" method="post" name="Checkout">
					<input value="Checkout" type="submit" disabled>
					<br>
					<i>You must be logged in to checkout.</i>
				</form>
				</c:if>
				<c:if test="${Account != null}">
				 <form style="vertical-align: middle; " target="_top" action="checkoutFS.jsp" method="post" name="Checkout">
					<input value="Checkout" type="submit">
				</form>
				</c:if>
				
		</td>
		<td style="vertical-align: top; text-align: right; width: 100px;"><br>
			Subtotal: <br>
			Federal Tax: <br>
			Provincial Tax: <br>
			Shipping: <br>
			<b>Total:</b> <br>
		</td>
		<td style="vertical-align: top; width: 100px;"><br>
			<fmt:formatNumber value="${Cart.calculateSubtotal()}" type="currency"/><br>
			<fmt:formatNumber value="${Cart.calculateFederalTax() }" type="currency"/> <br>
			<fmt:formatNumber value="${Cart.calculateProvincialTax() }" type="currency"/> <br>
			<fmt:formatNumber value="${Cart.getShippingRate() }" type="currency"/> <br>
			<b><fmt:formatNumber value="${Cart.getTotal() }" type="currency"/> </b><br> 
		</td>
	<tr>


</tbody>
</table>



</body>
</html>